﻿/************************** POST MESSAGE ***************/
#pragma once

#define DEVICE_NUM				(1)
#define ONE_DEVICE_DELAY_X		(3)
#define ONE_DEVICE_IO_O			(2)	 
#define ONE_DEVICE_AD			(2)	
#define ONE_DEVICE_DA			(2)	

#define ONE_DEVICE_DELAY_V		(ONE_DEVICE_DELAY_X*2-1)


typedef void (*DoRecvMsg)(void* pObj,char* buf, int len,SOCKET socket);



struct str_UpInfo_CorrSts
{    
	unsigned char sts[DEVICE_NUM];//1：正常，0：异常  
};
struct str_UpInfo_DevSts
{    
	unsigned char sts[DEVICE_NUM];//1：正常，0：异常  
};
struct str_UpInfo_Limit
{    
	unsigned char val[DEVICE_NUM];
};

struct str_UpInfo_FlashSts
{    
	unsigned char sts[DEVICE_NUM];//1：正常，0：异常  
};
struct str_UpInfo_Speaker
{    
	unsigned char open[DEVICE_NUM];//1：开，0：关
};

struct str_UpInfo_AD_IO
{    
	//AD
	double ad[DEVICE_NUM*ONE_DEVICE_AD];  
};


typedef void (*FunBakDevConn)(void);
typedef void (*FunBakDevSts)(str_UpInfo_DevSts* inst); 
typedef void (*FunBakCorrSts)(str_UpInfo_CorrSts* inst);
typedef void (*FunBakFlashSts)(str_UpInfo_FlashSts* inst); 
typedef void (*FunBakADIO)(str_UpInfo_AD_IO* inst);
typedef void (*FunBakSetIPSts)(unsigned char flashsts);
typedef void (*FunBakCmdSame)(void); 
 


#define TYPE_GET_ONE						0x10 //AD手动获取
#define TYPE_GET_TIME						0x11 //
#define TYPE_SET_IP						0x12 //IP设置
#define TYPE_SET_FLASH						0x13 //
#define TYPE_SET_ARGS						0x14 //   


#define TYPE_DEVSTS  						0x00 //
#define TYPE_GET							0x01 //
#define TYPE_CORRECT						0x02 // //
#define TYPE_FLASH  						0x04 //FLASH固化结果,dev to pc
#define TYPE_SET   							0x05 // 

#define TYPE_DEVCONN  						0x06 //

#define TYPE_DEBUG_READ_TDC					0x20 //
#define TYPE_DEBUG_READ_TDC_UP				0x21 //
#define TYPE_DEBUG_READ_TABLE				0x22 //
#define TYPE_DEBUG_READ_TABLE_UP			0x23 //

 
 


#define OP_NO							   0x00 //操作码_没有任何操作
#define OP_SAVE_FLASH					   0x01 //操作码_保存到FLASH 
#define OP_SET_VALID					   0x01 //操作码_设置有效

#define RES_SUCCESS						   0x0
#define RES_FAIL						   0x1



#define STS_TCP_LINK_SUCCESS			0
#define STS_TCP_LINK_FAIL				1
#define STS_ARG_ERROR					2

#define STS_TCP_CLOSE_SUCCESS			0
#define STS_TCP_CLOSE_FAIL				1

#define STS_TCP_SEND_SUCCESS   		    0
#define STS_TCP_SEND_FAIL   		    1//该状态等于 STS_TCP_LINK_FAIL

enum WORKMODE
{
	OUT_TRIG = 0,IN_TRIG,FOCUS,STOP
};

struct str_IP
{
	unsigned char ip[4];
	unsigned char mask[4];
	unsigned char gate[4];
	unsigned char port[4];
};

struct str_Flash
{
	bool     isNoChange[DEVICE_NUM];
	//延迟初始化
	unsigned int delayNs_x[DEVICE_NUM][ONE_DEVICE_DELAY_V];
	unsigned int delayPs_x[DEVICE_NUM][ONE_DEVICE_DELAY_V];
	unsigned int widthNs_x[DEVICE_NUM][ONE_DEVICE_DELAY_V];
	//unsigned int widthPs_x[DEVICE_NUM*ONE_DEVICE_DELAY_V];
	bool     isSaveV[DEVICE_NUM];

};

struct str_Args
{
	//模式
	WORKMODE mode;//工作模式OUT_TRIG：外触发,IN_TRIG：内触发,FOCUS模式：可定制PWM,STOP：停止
	unsigned char     chl_en_x[DEVICE_NUM][ONE_DEVICE_DELAY_X];//精延迟通道使能，在此可对每个延时通道的输出进行禁止和使能 
	bool     isSetMode[DEVICE_NUM];//模式开关，技术人员开发时建议固定设置true


	//focus_width 
	unsigned int widthNs_f;  //FOCUS模式下，精延迟的信号的宽度 
	unsigned int m_iPeriodNs_f;	//周期 

	//精延迟，将延时和脉宽的时间分成ns和ps两段，比如设置123.456ns，那么delayNs_x=123，delayPs_x=4560;
	unsigned int delayNs_x[DEVICE_NUM][ONE_DEVICE_DELAY_X];
	unsigned int delayPs_x[DEVICE_NUM][ONE_DEVICE_DELAY_X];
	unsigned int widthNs_x[DEVICE_NUM][ONE_DEVICE_DELAY_X];
	unsigned int widthPs_x[DEVICE_NUM][ONE_DEVICE_DELAY_X];
	bool     isSetX[DEVICE_NUM];
	//IO
	unsigned char io_o[DEVICE_NUM][ONE_DEVICE_IO_O];
	bool     isSetIO[DEVICE_NUM];//GPO开关，技术人员开发时建议固定设置true
	//DA
	double da[DEVICE_NUM][ONE_DEVICE_DA];
	bool     isSetDA[DEVICE_NUM];//DA电压开关，技术人员开发时建议固定设置true

};
